package com.leyou.item.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("category")
public class CategoryController {

    private final CategoryService categoryService;

    public CategoryController(CategoryService categoryService) {
        this.categoryService = categoryService;
    }

    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> ofParent(@RequestParam("pid")Long pid){
        List<CategoryDTO> categoryDTOS = categoryService.ofParent(pid);
        return ResponseEntity.ok(categoryDTOS);
    }

    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> getCategoryPyId(@PathVariable("id")Long id){
        CategoryDTO categoryDTO = categoryService.getCategoryPyId(id);
        return ResponseEntity.ok(categoryDTO);
    }

    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> getCategoryPyIds(@RequestParam("ids")List<Long> ids){
        List<CategoryDTO> categoryDTOS = categoryService.getCategoryPyIds(ids);
        return ResponseEntity.ok(categoryDTOS);
    }

    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> getCategoryPyBrandId(@RequestParam("id")Long bid){
        List<CategoryDTO> categoryDTOS = categoryService.getCategoryPyBrandId(bid);
        return ResponseEntity.ok(categoryDTOS);
    }


}
